home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-07 | 7.2 KB | 283 lines | [TEXT/ttxt] |
- //
- // html.lib
- //
- // This is a library for outputing forms from CGI scripts using CMMCGI.
- //
- // These routines make form output a breeze. You end up with code that
- // looks like the form it will generate using these style guidelines.
- //
- // CGIOUT(
- // HTML(
- // HEAD(
- // TITLE("This is the title for a form")
- // ),
- // BODY(
- // H2("This is the body for a form")
- // )
- // )
- // )
- //
- // The above is a series of function calls all returning strings
- // that results in a form being built. CGIOUT takes care of returning
- // the form over the CGI interface on the system the script is run on.
- //
- // Don't forget to add the appropriate number of commas in between
- // function arguments.
- // ----------------------------------------------------------------------
-
- // This is like a sprintf, except it returns a string containing the result.
- // for example: retPrintf("%s %d %s",string1, int1, string2);
- retPrintf(FormatString/*,args*/)
- {
- va_start(VaList,FormatString);
- vsprintf(RetStr,FormatString,VaList);
- va_end(VaList);
- return RetStr;
- }
-
- // Take all the command line args and append them together in one string
- ArgAppend(ArgCount,VaList,SkipCount)
- {
- RetStr = "";
- for ( ArgIdx = SkipCount; ArgIdx < ArgCount; ArgIdx++ )
- strcat(RetStr,va_arg(VaList,ArgIdx));
-
- va_end(VaList);
- return RetStr;
- }
-
- // some convienient defines for calling arg append
- #define APPEND_ALL ArgAppend(va_start(VaList),VaList,0)
- #define APPEND_ALL_1 ArgAppend(va_start(VaList),VaList,1)
- #define APPEND_ALL_2 ArgAppend(va_start(VaList),VaList,2)
-
- // defines for the HTML tags that don't require end tags
- #define LINEBREAK "<BR>"
- #define BR "<BR>"
- #define HR "<HR>"
- #define ISINDEX "<ISINDEX>"
- #define P "<P>"
- #define ENDP "</P>"
-
- // The HTML tag functions starthere. We included all HTML 2.0
- // tags. Where there are many possible attributes, you need
- // to fill them in yourself. If you improve this library, please
- // send it to Nombas. If you have HTML questions, look at html2_0.doc
-
- // ANCHOR - requires href, and attr. If you don't need any attributes make
- // sure to put a null string - ""
- ANCHOR(hRef,attr)
- {
- return strcat(retPrintf("<A HREF=\"%s\" %s>",hRef,attr),APPEND_ALL_2,"</A>");
- }
- // Address - appends all parameters between the tags
- ADDRESS()
- {
- return strcat("<ADDRESS>",APPEND_ALL,"</ADDRESS>\n");
- }
- // Bold - appends all parameters between the tags
- B()
- {
- return strcat("<B>",APPEND_ALL,"</B>\n");
- }
- // Base - requires the href to be used for the base of this html doc
- BASE(href)
- {
- return strcat(`<BASE HREF="`,href,`">`);
- }
- // Blockquote - appends all parameters between the tags
- BLOCKQUOTE()
- {
- return strcat("<BLOCKQUOTE>",APPEND_ALL,"</BLOCKQUOTE>\n");
- }
- // Body - appends all parameters between the tags
- BODY()
- {
- return strcat("<BODY>",APPEND_ALL,"</BODY>\n");
- }
- // Bodytext - appends all parameters between the tags
- BODYTEXT()
- {
- return strcat("<BODYTEXT>",APPEND_ALL,"</BODYTEXT>\n");
- }
- // Cite - appends all parameters between the tags
- CITE()
- {
- return strcat("<CITE>\n",APPEND_ALL,"\n<CITE/>\n");
- }
- // Code - appends all parameters between the tags
- CODE()
- {
- return strcat("<CODE>",APPEND_ALL,"</CODE>\n");
- }
- // DD - appends all parameters after the tag
- DD()
- {
- return strcat("<DD>",APPEND_ALL);
- }
- // DIR - appends all parameters between the tags
- DIR()
- {
- return strcat("<DIR>\n",APPEND_ALL,"\n</DIR>\n");
- }
- // DL - appends all parameters between the tags
- DL()
- {
- return strcat("<DL>\n",APPEND_ALL,"</DL>\n");
- }
- // DT - appends all parameters after the tag
- DT()
- {
- return strcat("<DT>",APPEND_ALL);
- }
- // EM - appends all parameters between the tags
- EM()
- {
- return strcat("<EM>",APPEND_ALL,"</EM>\n");
- }
- // Bold - appends all parameters between the tags and adds the attributes
- // in the FORM tag
- FORM(attr)
- {
- return strcat(retPrintf("<FORM %s>",attr),APPEND_ALL_1,"</FORM>");
- }
- // Head - appends all parameters between the tags
- HEAD()
- {
- return strcat("<HEAD>",APPEND_ALL,"</HEAD>\n");
- }
- // Heading - appends all parameters between the tags to the appropriate
- // H-level ie H1, H2, ...
- HEADING(Level)
- {
- return strcat(retPrintf("<H%d>",Level),APPEND_ALL_1,retPrintf("</H%d>",Level));
- }
- // H1-H6 - appends all parameters between the tags
- H1()
- {
- return strcat("<H1>",APPEND_ALL,"</H1>\n");
- }
- H2()
- {
- return strcat("<H2>",APPEND_ALL,"</H2>\n");
- }
- H3()
- {
- return strcat("<H3>",APPEND_ALL,"</H3>\n");
- }
- H4()
- {
- return strcat("<H4>",APPEND_ALL,"</H4>\n");
- }
- H5()
- {
- return strcat("<H5>",APPEND_ALL,"</H5>\n");
- }
- H6()
- {
- return strcat("<H6>",APPEND_ALL,"</H6>\n");
- }
- // HTML - appends all parameters between the tags and adds the attributes
- // to the HTML tag. If there are no attributes, use a null string ""
- HTML(attr)
- {
- if (defined(_MAC_))
- return strcat(retPrintf("<HTML %s>",attr),APPEND_ALL_1,"</HTML>");
- else
- return strcat(retPrintf(
- "Content-Type: text/html\n\n\n<HTML %s>",attr),APPEND_ALL_1,"</HTML>");
- }
- // Italicize - appends all parameters between the tags
- I()
- {
- return strcat("<I>\n",APPEND_ALL,"</I>\n");
- }
- // Image - appends all parameters between the tagsas image attributes and
- // sets the image URL
- IMG(image)
- {
- return strcat(retPrintf("<IMG SRC=\"%s\" ",image),APPEND_ALL_1,">\n");
- }
- // Input - appends all parameters between the tags as input attributes and
- // sets the input to the type specified
- INPUT(type)
- {
- return strcat(retPrintf("<INPUT TYPE=%s ",type),APPEND_ALL_1,">\n");
- }
- // KBD - appends all parameters between the tags
- KBD()
- {
- return strcat("<KBD>",APPEND_ALL,"</KBD>\n");
- }
- // List Item - appends all parameters after the list item tag
- LI()
- {
- return strcat("<LI>",APPEND_ALL);
- }
- // Link - appends all parameters between the tags
- LINK(attr)
- {
- return retPrintf("<LINK %s>",attr);
- }
- // Menu - appends all parameters between the tags should be menu items
- MENU()
- {
- return strcat("<MENU>\n",APPEND_ALL,"</MENU>\n");
- }
- // OL - appends all parameters between the tags should be list items
- OL()
- {
- return strcat("<OL>\n",APPEND_ALL,"</OL>\n");
- }
- // OPTION - set the option attributes and appends other parameters after
- OPTION(attr)
- {
- return strcat(retPrintf("<OPTION %s>",attr),APPEND_ALL_1,"\n");
- }
- // Preformatted - appends all parameters between the tags
- PRE()
- {
- return strcat("<PRE>\n",APPEND_ALL,"</PRE>\n");
- }
- // Sample - appends all parameters between the tags
- SAMP()
- {
- return strcat("<SAMP>",APPEND_ALL,"</SAMP>\n");
- }
- // Select - appends all parameters between the tags
- SELECT()
- {
- return strcat("<SELECT>\n",APPEND_ALL,"</SELECT>\n");
- }
- // Strong - appends all parameters between the tags
- STRONG()
- {
- return strcat("<STRONG>",APPEND_ALL,"</STRONG>\n");
- }
- // Text Area - sets the attributes
- TEXTAREA(attr)
- {
- return retPrintf("<TEXTAREA %s>\n",attr);
- }
- // Title - appends all parameters between the tags
- TITLE()
- {
- return strcat("<TITLE>",APPEND_ALL,"</TITLE>\n");
- }
- // TT - appends all parameters between the tags
- TT()
- {
- return strcat("<TT>",APPEND_ALL,"</TT>\n");
- }
- // Unnumbered list - appends all parameters between the tags
- // should be list items
- UL()
- {
- return strcat("<UL>\n",APPEND_ALL,"</UL>\n");
- }
- // Variable - appends all parameters between the tags as variable text
- VAR()
- {
- return strcat("<VAR>",APPEND_ALL,"</VAR>\n");
- }
-